home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / man / lib.fmt / c / Td.man < prev    next >
Encoding:
Text File  |  1990-04-09  |  43.5 KB  |  927 lines

  1.  
  2.  
  3.  
  4. Td                    C Library Procedures                     Td
  5.  
  6.  
  7.  
  8. _________________________________________________________________
  9.  
  10. NNAAMMEE
  11.      Td_Create, Td_Delete, Td_PutRaw,  Td_GetRaw,  Td_ControlRaw,
  12.      Td_Open,      Td_Close,      Td_PutCooked,     Td_GetCooked,
  13.      Td_ControlCooked, Td_CreatePdev,  Td_DeletePdev  -  Terminal
  14.      driver implementing 4.3 BSD operations.
  15.  
  16. SSYYNNOOPPSSIISS
  17.      ##iinncclluuddee <<ttdd..hh>>
  18.  
  19.      Td_Terminal
  20.      TTdd__CCrreeaattee(_b_u_f_f_e_r_S_i_z_e, _c_o_o_k_e_d_P_r_o_c, _c_o_o_k_e_d_D_a_t_a, _r_a_w_P_r_o_c, _r_a_w_D_a_t_a)
  21.  
  22.      TTdd__DDeelleettee(_t_e_r_m_i_n_a_l)
  23.  
  24.      TTdd__PPuuttRRaaww(_t_e_r_m_i_n_a_l, _n_u_m_B_y_t_e_s, _b_u_f_f_e_r)
  25.  
  26.      int
  27.      TTdd__GGeettRRaaww(_t_e_r_m_i_n_a_l, _n_u_m_B_y_t_e_s, _b_u_f_f_e_r)
  28.  
  29.      TTdd__CCoonnttrroollRRaaww(_t_e_r_m_i_n_a_l, _o_p_e_r_a_t_i_o_n)
  30.  
  31.      int
  32.      TTdd__OOppeenn(_t_e_r_m_i_n_a_l, _s_e_l_e_c_t_B_i_t_s_P_t_r)
  33.  
  34.      TTdd__CClloossee(_t_e_r_m_i_n_a_l)
  35.  
  36.      int
  37.      TTdd__PPuuttCCooookkeedd(_t_e_r_m_i_n_a_l, _n_u_m_B_y_t_e_s_P_t_r, _b_u_f_f_e_r, _s_i_g_N_u_m_P_t_r, _s_e_l_e_c_t_B_i_t_s_P_t_r)
  38.  
  39.      int
  40.      TTdd__GGeettCCooookkeedd(_t_e_r_m_i_n_a_l, _p_I_D, _f_a_m_i_l_y_I_D, _n_u_m_B_y_t_e_s_P_t_r, _b_u_f_f_e_r, _s_i_g_N_u_m_P_t_r, _s_e_l_e_c_t_B_i_t_s_P_t_r)
  41.  
  42.      int
  43.      TTdd__CCoonnttrroollCCooookkeedd(_t_e_r_m_i_n_a_l, _c_o_m_m_a_n_d, _i_n_p_u_t_S_i_z_e, _i_n_p_u_t, _o_u_t_p_u_t_S_i_z_e_P_t_r, _o_u_t_p_u_t, _s_i_g_N_u_m_P_t_r, _s_e_l_e_c_t_B_i_t_s_P_t_r)
  44.  
  45.      Td_Pdev
  46.      TTdd__CCrreeaatteePPddeevv(_n_a_m_e, _r_e_a_l_N_a_m_e_P_t_r, _t_e_r_m_P_t_r, _r_a_w_P_r_o_c, _r_a_w_D_a_t_a)
  47.  
  48.      TTdd__DDeelleetteePPddeevv(_t_t_y_P_d_e_v)
  49.  
  50. AARRGGUUMMEENNTTSS
  51.      int           _b_u_f_f_e_r_S_i_z_e        (in)      Size   of   output
  52.                                                buffer  to use for
  53.                                                terminal.  This is
  54.                                                not    an    exact
  55.                                                specification,  in
  56.                                                that  the terminal
  57.                                                driver  may  actu-
  58.                                                ally   allow  more
  59.                                                characters    than
  60.  
  61.  
  62.  
  63. Sprite v.1.0         Printed:  April 9, 1990                    1
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. Td                    C Library Procedures                     Td
  71.  
  72.  
  73.  
  74.                                                this  to  be  buf-
  75.                                                fered, but it will
  76.                                                always   allow  at
  77.                                                least  this   many
  78.                                                characters  to  be
  79.                                                buffered.
  80.  
  81.      int           (*_c_o_o_k_e_d_P_r_o_c)()   (in)      Procedure to  call
  82.                                                for control opera-
  83.                                                tions  on   cooked
  84.                                                side of driver.
  85.  
  86.      ClientData    _c_o_o_k_e_d_D_a_t_a        (in)      Additional   value
  87.                                                to  pass  to _c_o_o_k_-
  88.                                                _e_d_P_r_o_c.
  89.  
  90.      int           (*_r_a_w_P_r_o_c)()      (in)      Procedure to  call
  91.                                                for control opera-
  92.                                                tions on raw  side
  93.                                                of driver.
  94.  
  95.      ClientData    _r_a_w_D_a_t_a           (in)      Additional   value
  96.                                                to     pass     to
  97.                                                _r_a_w_P_r_o_c.
  98.  
  99.      Td_Terminal   _t_e_r_m_i_n_a_l          (in)      Token  for  termi-
  100.                                                nal;    must  have
  101.                                                been  returned  by
  102.                                                some previous call
  103.                                                to TTdd__CCrreeaattee.
  104.  
  105.      int           _n_u_m_B_y_t_e_s          (in)      Total  number   of
  106.                                                bytes  to  get  or
  107.                                                put  for/from  raw
  108.                                                side of terminal.
  109.  
  110.      char          *_b_u_f_f_e_r           (in/out)  Buffer  containing
  111.                                                characters  to  be
  112.                                                written,  or  con-
  113.                                                taining  space  in
  114.                                                which   to   place
  115.                                                characters   being
  116.                                                read.
  117.  
  118.      int           _o_p_e_r_a_t_i_o_n         (in)      Control  operation
  119.                                                being invoked from
  120.                                                raw side of termi-
  121.                                                nal.  Currently no
  122.                                                operations     are
  123.                                                defined.
  124.  
  125.      int           *_s_e_l_e_c_t_B_i_t_s_P_t_r    (in/out)  Points   to   word
  126.  
  127.  
  128.  
  129. Sprite v.1.0         Printed:  April 9, 1990                    2
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. Td                    C Library Procedures                     Td
  137.  
  138.  
  139.  
  140.                                                whose         bits
  141.                                                (FFSS__RREEAADDAABBLLEE   and
  142.                                                FFSS__WWRRIITTAABBLLEE) indi-
  143.                                                cate whether  read
  144.                                                or   write  opera-
  145.                                                tions can complete
  146.                                                successfully.
  147.                                                Different     pro-
  148.                                                cedures may modify
  149.                                                either or both  of
  150.                                                these bits.
  151.  
  152.      int           *_n_u_m_B_y_t_e_s_P_t_r      (in/out)  Points to  maximum
  153.                                                number of bytes to
  154.                                                read   or   write.
  155.                                                Gets   overwritten
  156.                                                with actual number
  157.                                                of  bytes  read or
  158.                                                written.
  159.  
  160.      int           *_s_i_g_N_u_m_P_t_r        (out)     Overwritten   with
  161.                                                signal  number  to
  162.                                                apply to  invoking
  163.                                                process.      Zero
  164.                                                means no signal.
  165.  
  166.      int           _p_I_D               (in)      Identifier of pro-
  167.                                                cess      invoking
  168.                                                operation.
  169.  
  170.      int           _f_a_m_i_l_y_I_D          (in)      Process group that
  171.                                                _p_I_D belongs to.
  172.  
  173.      int           _c_o_m_m_a_n_d           (in)      Number  of  IOCon-
  174.                                                trol    operation.
  175.                                                Note:   these  are
  176.                                                Sprite   IOControl
  177.                                                numbers, not  UNIX
  178.                                                ioctl     numbers.
  179.                                                See    <<ddeevv//ttttyy..hh>>
  180.                                                for definitions.
  181.  
  182.      int           _i_n_p_u_t_S_i_z_e         (in)      Number of bytes of
  183.                                                information     in
  184.                                                _i_n_p_u_t
  185.  
  186.      char          *_i_n_p_u_t            (in)      Input  buffer  for
  187.                                                IOControl   opera-
  188.                                                tion.  Its  struc-
  189.                                                ture   depends  on
  190.                                                the IOControl.
  191.  
  192.  
  193.  
  194.  
  195. Sprite v.1.0         Printed:  April 9, 1990                    3
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. Td                    C Library Procedures                     Td
  203.  
  204.  
  205.  
  206.      int           *_o_u_t_p_u_t_S_i_z_e_P_t_r    (in/out)  Points   to   word
  207.                                                specifiying  total
  208.                                                number of bytes of
  209.                                                output      buffer
  210.                                                space available at
  211.                                                _o_u_t_p_u_t.   Modified
  212.                                                to hold the actual
  213.                                                number  of  output
  214.                                                bytes provided  by
  215.                                                the IOControl.
  216.  
  217.      char          *_o_u_t_p_u_t           (in)      Output buffer  for
  218.                                                IOControl   opera-
  219.                                                tion.  Its  struc-
  220.                                                ture   depends  on
  221.                                                the IOControl.
  222.  
  223.      char          *_n_a_m_e             (in)      Name  of  file  to
  224.                                                use  for  terminal
  225.                                                pseudo-device.
  226.                                                May be either full
  227.                                                name or root.
  228.  
  229.      char          **_r_e_a_l_N_a_m_e_P_t_r     (out)     Where   to   store
  230.                                                actual   name   of
  231.                                                terminal   pseudo-
  232.                                                device used.  NULL
  233.                                                means  _n_a_m_e  is  a
  234.                                                root;     non-NULL
  235.                                                means _n_a_m_e is  the
  236.                                                full path name.
  237.  
  238.      Td_Terminal   *_t_e_r_m_P_t_r          (out)     If non-NULL, token
  239.                                                for  terminal gets
  240.                                                stored in the word
  241.                                                pointed    to   by
  242.                                                _t_e_r_m_P_t_r.
  243.  
  244.      Td_Pdev       _t_t_y_P_d_e_v           (in)      Token          for
  245.                                                terminal-driven
  246.                                                pseudo-device   to
  247.                                                destroy.      Must
  248.                                                have been returned
  249.                                                previously      by
  250.                                                TTdd__CCrreeaatteePPddeevv.
  251.  
  252. _________________________________________________________________
  253.  
  254.  
  255. IINNTTRROODDUUCCTTIIOONN
  256.      The Td library procedures implement a terminal  driver  with
  257.      the  same features as the terminal driver implemented in the
  258.      4.3 BSD kernel.  The  data  structures  managed  by  the  Td
  259.      library  are  called  Td_Terminals  and have two interfaces:
  260.  
  261.  
  262.  
  263. Sprite v.1.0         Printed:  April 9, 1990                    4
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270. Td                    C Library Procedures                     Td
  271.  
  272.  
  273.  
  274.      cooked and raw.  The raw interface is  used  to  communicate
  275.      between   the   Td   procedures  and  the  low-level  device
  276.      corresponding to the terminal (usually a serial line  device
  277.      or  a  window on a screen).  The cooked interface is used to
  278.      communicate with processes accessing the 4.3-BSD-like termi-
  279.      nal.   In  between, the Td library provides input and output
  280.      character buffering, echoing and line editing, flow control,
  281.      interrupt  characters, and all the other features of the 4.3
  282.      BSD terminal driver.
  283.  
  284.      Each of the cooked and raw interfaces has at least four pro-
  285.      cedures  associated  with  it.   Three of the procedures are
  286.      provided by Td:  one to pass characters  into  the  terminal
  287.      driver  (e.g.  a  character  that was just typed on the key-
  288.      board, or a character that a user process wishes to ouput on
  289.      the  terminal),  one to extract characters from the terminal
  290.      driver (e.g. to pass them to a waiting user process,  or  to
  291.      output  them  onto  the terminal), and one to invoke control
  292.      operations on the terminal.  The fourth procedure  for  each
  293.      interface  is  provided by the program in which Td is embed-
  294.      ded.  These procedures are called back by Td to  notify  the
  295.      program  of various events, for example, that characters are
  296.      waiting in the terminal's output buffer, or that a full line
  297.      is present in the terminal's input buffer.
  298.  
  299.      Most of the procedures in the Td library are generic in that
  300.      they  can  be  used  in many different situations, including
  301.      both user programs and the Sprite  kernel.   Two  additional
  302.      procedures,  TTdd__CCrreeaatteePPddeevv and TTdd__DDeelleetteePPddeevv are provided to
  303.      connect the cooked side of a Td_Terminal to a pseudo-device.
  304.      These procedures are used by user-level Sprite programs like
  305.      rrllooggiinndd and window-based terminal emulators.
  306.  
  307.  
  308. CCRREEAATTIINNGG AANNDD DDEELLEETTIINNGG TTEERRMMIINNAALLSS
  309.      The TTdd__CCrreeaattee procedure is used to create a Td_Terminal.  It
  310.      returns  a token that must be passed to most of the other Td
  311.      procedures.  Several Td_Terminals  may  exist  at  the  same
  312.      time,  each  created  by a separate call to TTdd__CCrreeaattee.  Each
  313.      Td_Terminal corresponds to one logical terminal with its own
  314.      input  and  output buffers.  The _c_o_o_k_e_d_P_r_o_c and _r_a_w_P_r_o_c pro-
  315.      cedures, and their associated ClientData values, are used to
  316.      invoke  control operations on the two sides of the terminal.
  317.      The use of these two procedures is described in the sections
  318.      below.   The _b_u_f_f_e_r_S_i_z_e argument is described in the BBUUFFFFEERR--
  319.      IINNGG section below.
  320.  
  321.      TTdd__DDeelleettee simulates a hangup on a Td_Terminal, then destroys
  322.      all  of the state associated with the terminal.  After it is
  323.      called, the _t_e_r_m_i_n_a_l argument should never be used again  by
  324.      the caller.
  325.  
  326.  
  327.  
  328.  
  329. Sprite v.1.0         Printed:  April 9, 1990                    5
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336. Td                    C Library Procedures                     Td
  337.  
  338.  
  339.  
  340. RRAAWW IINNTTEERRFFAACCEE
  341.      The raw interface is used to communicate between the  termi-
  342.      nal driver and the ``dumb'' terminal device.  It consists of
  343.      the three procedures  TTdd__PPuuttRRaaww,  TTdd__GGeettRRaaww,  TTdd__CCoonnttrroollRRaaww,
  344.      and the _r_a_w_P_r_o_c procedure passed to TTdd__CCrreeaattee.
  345.  
  346.      When characters are typed on the  keyboard  associated  with
  347.      the  raw  terminal,  they  should  be passed to the temrinal
  348.      driver by calling TTdd__PPuuttRRaaww.  The Td library will then  per-
  349.      form input processing such as echoing and line editing.
  350.  
  351.      The procedure TTdd__GGeettRRaaww should be invoked to remove  charac-
  352.      ters  from  the  terminal's  output  buffer and copy them to
  353.      _b_u_f_f_e_r.  The return value indicates how many characters were
  354.      actually  copied,  up to either _n_u_m_B_y_t_e_s or the total number
  355.      of characters in the output buffer.   The  return  value  is
  356.      zero if the output buffer is empty.  The caller of TTdd__GGeettRRaaww
  357.      should then pass the characters to the raw serial device, or
  358.      display them on the screen if the terminal is being emulated
  359.      in a window.  Note that it is up to the application in which
  360.      Td  is  embedded to decide when to call TTdd__GGeettRRaaww.  However,
  361.      Td  calls  _r_a_w_P_r_o_c  to  notify  the  application  that   the
  362.      terminal's output buffer contains characters;  see below for
  363.      details.
  364.  
  365.      The procedure TTdd__CCoonnttrroollRRaaww should be  called  when  certain
  366.      interesting events occur on the raw terminal.  The _o_p_e_r_a_t_i_o_n
  367.      argument identifies the event that occurred, and must be one
  368.      of:
  369.  
  370.           TTDD__BBRREEAAKK            Means that a break just occurred on
  371.                               the   raw   device.   TTdd__CCoonnttrroollRRaaww
  372.                               should  only  be  called  when  the
  373.                               break condition ends.
  374.  
  375.           TTDD__GGOOTT__CCAARRRRIIEERR      Means that  there  is  now  carrier
  376.                               present  on  the raw device (e.g. a
  377.                               modem connection was just made).
  378.  
  379.           TTDD__LLOOSSTT__CCAARRRRIIEERR     Means that carrier just  went  away
  380.                               on  the  raw device (e.g. the party
  381.                               on  the  other  end  hung  up   the
  382.                               phone).
  383.  
  384.      The Td module will invoke the procedure _r_a_w_P_r_o_c,  which  was
  385.      passed  to  TTdd__CCrreeaattee, to ask for special actions on the raw
  386.      terminal device, or to provide additional  information  that
  387.      may  be useful in managing the raw terminal device.  _R_a_w_P_r_o_c
  388.      must have the following structure:
  389.  
  390.           int
  391.           rawProc(rawData, operation, inputSize, input, outputSize, output)
  392.  
  393.  
  394.  
  395. Sprite v.1.0         Printed:  April 9, 1990                    6
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402. Td                    C Library Procedures                     Td
  403.  
  404.  
  405.  
  406.               ClientData rawData;
  407.               int operation;
  408.               int inputSize;
  409.               char *input;
  410.               int outputSize;
  411.               char *output;
  412.           {
  413.            ...
  414.           }
  415.      The _r_a_w_D_a_t_a argument will be the same as the  _r_a_w_D_a_t_a  argu-
  416.      ment  passed  to  TTdd__CCrreeaattee.   It  usually  refers to a data
  417.      structure describing the raw device, which will be  used  by
  418.      _r_a_w_P_r_o_c.   The  _o_p_e_r_a_t_i_o_n parameter gives the reason for the
  419.      call, the _i_n_p_u_t_S_i_z_e and _i_n_p_u_t arguments describe an area  of
  420.      data  that Td is making available to _r_a_w_P_r_o_c, and _o_u_t_p_u_t_S_i_z_e
  421.      and _o_u_t_p_u_t describe a buffer in which _r_a_w_P_r_o_c may place data
  422.      that  it  wishes  to  return  to  Td.  The return value from
  423.      _r_a_w_P_r_o_c indicates how  many  bytes  of  data  were  actually
  424.      placed  at  _o_u_t_p_u_t;  it must not be greater than _o_u_p_t_u_t_S_i_z_e.
  425.      At present, _o_p_e_r_a_t_i_o_n must be one of the following:
  426.  
  427.           TTDD__RRAAWW__SSTTAARRTT__BBRREEAAKK            Initiate a  break  condi-
  428.                                         tion  on  the raw device,
  429.                                         if  the  device  supports
  430.                                         it.   There  is  no input
  431.                                         data or output  data  for
  432.                                         this operation.
  433.  
  434.           TTDD__RRAAWW__SSTTOOPP__BBRREEAAKK             End a break condition  on
  435.                                         the  raw  device,  if the
  436.                                         device    supports    it.
  437.                                         There is no input data or
  438.                                         output  data   for   this
  439.                                         operation.
  440.  
  441.           TTDD__RRAAWW__SSEETT__DDTTRR                Set the  ``data  terminal
  442.                                         ready''  condition on the
  443.                                         raw device,  if  it  sup-
  444.                                         ports  such an operation.
  445.                                         There is no input data or
  446.                                         output   data   for  this
  447.                                         operation.
  448.  
  449.           TTDD__RRAAWW__CCLLEEAARR__DDTTRR              Clear the ``data terminal
  450.                                         ready''  condition on the
  451.                                         raw device,  if  it  sup-
  452.                                         ports  such an operation.
  453.                                         There is no input data or
  454.                                         output   data   for  this
  455.                                         operation.
  456.  
  457.           TTDD__RRAAWW__SSHHUUTTDDOOWWNN               The  terminal  has   been
  458.  
  459.  
  460.  
  461. Sprite v.1.0         Printed:  April 9, 1990                    7
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468. Td                    C Library Procedures                     Td
  469.  
  470.  
  471.  
  472.                                         closed  and is being shut
  473.                                         down.   The  raw   device
  474.                                         should  now  be shut down
  475.                                         too  (e.g.  hang   up   a
  476.                                         modem).    There   is  no
  477.                                         input data or output data
  478.                                         for this operation.
  479.  
  480.           TTDD__RRAAWW__OOUUTTPPUUTT__RREEAADDYY           This operation  indicates
  481.                                         that  the  output  buffer
  482.                                         for the terminal has just
  483.                                         become   non-empty.    At
  484.                                         some point in the future,
  485.                                         the   application  should
  486.                                         invoke TTdd__GGeettRRaaww and out-
  487.                                         put the characters to the
  488.                                         device.   There   is   no
  489.                                         input data or output data
  490.                                         for this operation.
  491.  
  492.           TTDD__RRAAWW__FFLLUUSSHH__OOUUTTPPUUTT           If there are any  charac-
  493.                                         ters  buffered for output
  494.                                         on the raw device but not
  495.                                         yet  output,  they should
  496.                                         be discarded without out-
  497.                                         putting  them.   There is
  498.                                         no input data  or  output
  499.                                         data for this operation.
  500.  
  501.           TTDD__RRAAWW__FFLLOOWW__CCHHAARRSS             The flow-control  charac-
  502.                                         ters   for  the  terminal
  503.                                         have just been  modified.
  504.                                         The _i_n_p_u_t argument points
  505.                                         to a structure  with  the
  506.                                         following format:
  507.  
  508.                                         typedef struct {
  509.                                             char stop;
  510.                                             char start;
  511.                                         } Td_FlowChars;
  512.  
  513.                                         Whenever _s_t_o_p is received
  514.                                         from  the  raw  terminal,
  515.                                         output should be  stopped
  516.                                         until  _s_t_a_r_t is received.
  517.                                         _S_t_o_p and _s_t_a_r_t may be the
  518.                                         same   character.    This
  519.                                         call is made so that  the
  520.                                         driver for the raw device
  521.                                         may implement  flow  con-
  522.                                         trol directly in order to
  523.                                         provide  faster  response
  524.  
  525.  
  526.  
  527. Sprite v.1.0         Printed:  April 9, 1990                    8
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534. Td                    C Library Procedures                     Td
  535.  
  536.  
  537.  
  538.                                         to  the  _s_t_a_r_t  and  _s_t_o_p
  539.                                         characters.  The raw dev-
  540.                                         ice   driver  may  ignore
  541.                                         these  calls  and  simply
  542.                                         pass   the  flow  control
  543.                                         characters to the  termi-
  544.                                         nal driver, in which case
  545.                                         Td  will  implement  flow
  546.                                         control,    albeit   with
  547.                                         slower   response.     If
  548.                                         either  _s_t_o_p  or _s_t_a_r_t is
  549.                                         -1, then the  raw  driver
  550.                                         must  not  implement flow
  551.                                         control.   There  is   no
  552.                                         output   data   for  this
  553.                                         operation.
  554.  
  555.           TTDD__RRAAWW__SSEETT__BBAAUUDD__RRAATTEE          Someone has just asked to
  556.                                         change  the baud rate for
  557.                                         the  device.   Both   the
  558.                                         _i_n_p_u_t  and  _o_u_t_p_u_t  argu-
  559.                                         ments point to structures
  560.                                         with  the  following for-
  561.                                         mat:
  562.  
  563.                                         typedef struct {
  564.                                             char ispeed;
  565.                                             char ospeed;
  566.                                         } Td_BaudRate;
  567.  
  568.                                         The  iissppeeeedd  and   oossppeeeedd
  569.                                         fields   have   the  same
  570.                                         values as they  would  in
  571.                                         an ssggttttyybb structure, such
  572.                                         as  BB99660000.    The   _i_n_p_u_t
  573.                                         argument     gives    the
  574.                                         requested   baud   rates.
  575.                                         _R_a_w_P_r_o_c may either accept
  576.                                         these speeds or  override
  577.                                         them   and   return   the
  578.                                         actual speeds it used  in
  579.                                         the  _o_u_t_p_u_t area.  If the
  580.                                         _i_n_p_u_t     speeds      are
  581.                                         accepted,   then  _r_a_w_P_r_o_c
  582.                                         need not modify the  _o_u_t_-
  583.                                         _p_u_t  area;  it can simply
  584.                                         return 0.
  585.  
  586.           TTDD__RRAAWW__GGEETT__BBAAUUDD__RRAATTEE          This operation is invoked
  587.                                         to   fetch   the  current
  588.                                         input and  output  speeds
  589.                                         for   the   raw   device.
  590.  
  591.  
  592.  
  593. Sprite v.1.0         Printed:  April 9, 1990                    9
  594.  
  595.  
  596.  
  597.  
  598.  
  599.  
  600. Td                    C Library Procedures                     Td
  601.  
  602.  
  603.  
  604.                                         There is no  _i_n_p_u_t  area,
  605.                                         but  _o_u_t_p_u_t  refers  to a
  606.                                         TTdd__BBaauuddRRaattee structure  as
  607.                                         described    above    for
  608.                                         TTDD__RRAAWW__SSEETT__BBAAUUDD__RRAATTEE.
  609.                                         _R_a_w_P_r_o_c  should  fill  in
  610.                                         the  current  speeds  for
  611.                                         the device at *_o_u_t_p_u_t and
  612.                                         return
  613.                                         ssiizzeeooff((TTdd__BBaauuddRRaattee)).
  614.  
  615.  
  616. CCOOOOKKEEDD IINNTTEERRFFAACCEE
  617.      The cooked interface is used to communicate between the ter-
  618.      minal  driver  and  the processes wishing to access a device
  619.      with full 4.3 BSD  terminal  semantics.   As  with  the  raw
  620.      interface, it consists of a collection of Td procedures that
  621.      the enclosing application invokes, plus one procedure in the
  622.      enclosing application that Td invokes.
  623.  
  624.      Whenever a process attempts to open the terminal device, the
  625.      procedure  TTdd__OOppeenn  should be called.  If the terminal is in
  626.      ``exclusive'' mode (meaning opens are being refused), then a
  627.      UNIX  error  number is returned.  Otherwise zero is returned
  628.      and the FFSS__RREEAADDAABBLLEE and FFSS__WWRRIITTAABBLLEE bits  of  *_s_e_l_e_c_t_B_i_t_s_P_t_r
  629.      are  set  to  indicate whether there are input characters or
  630.      output buffer space available, respectively.
  631.  
  632.      When the terminal is closed,  TTdd__CClloossee  should  be  invoked.
  633.      There  should  be exactly one TTdd__CClloossee call for each TTdd__OOppeenn
  634.      call:  if an open stream is dduupp-ed,  TTdd__CClloossee  shouldn't  be
  635.      called until the last dduupp-ed copy is closed.
  636.  
  637.      When  a  process  writes  data  to  the   cooked   terminal,
  638.      TTdd__PPuuttCCooookkeedd  should be invoked to pass the data to the ter-
  639.      minal  driver.   The  characters  will  be  added   to   the
  640.      terminal's  output buffer after performing output processing
  641.      on them.  The return value is always zero (meaning that  the
  642.      characters  are  always  accepted).   The FFSS__WWRRIITTAABBLLEE bit in
  643.      *_s_e_l_e_c_t_B_i_t_s_P_t_r  will  be  updated  to  reflect  whether  the
  644.      terminal's  output buffer is now ``full'' (see the BBUUFFFFEERRIINNGG
  645.      section below for more on what this means).  If so, then  no
  646.      more calls should be made to TTdd__PPuuttCCooookkeedd until the terminal
  647.      driver gives notice that there is more space in  the  output
  648.      buffer  (this  is  done  by  calling _c_o_o_k_e_d_P_r_o_c as described
  649.      below).  TTdd__PPuuttCCooookkeedd overwrites the  value  at  *_s_i_g_N_u_m_P_t_r;
  650.      if  the  value  written is non-zero then it is a UNIX signal
  651.      number that should be applied to the calling process.
  652.  
  653.      When a process wishes to read  characters  from  the  cooked
  654.      terminal,  TTdd__GGeettCCooookkeedd  should  be  called.  This procedure
  655.      will remove characters from the terminal's input buffer  (up
  656.  
  657.  
  658.  
  659. Sprite v.1.0         Printed:  April 9, 1990                   10
  660.  
  661.  
  662.  
  663.  
  664.  
  665.  
  666. Td                    C Library Procedures                     Td
  667.  
  668.  
  669.  
  670.      to *_n_u_m_B_y_t_e_s_P_t_r of them) and copy them to _b_u_f_f_e_r.  The value
  671.      at *_n_u_m_B_y_t_e_s_P_t_r will be updated to reflect the actual number
  672.      of  characters returned.  The return value from TTdd__GGeettCCooookkeedd
  673.      will normally be zero;   if  an  error  occurred,  then  the
  674.      return value will be a UNIX error number.  If the terminal's
  675.      input buffer is empty, then the return value will be EEWWOOUULLDD--
  676.      BBLLOOCCKK and *_n_u_m_B_y_t_e_s_P_t_r will be set to zero.  The FFSS__RREEAADDAABBLLEE
  677.      bit of *_s_e_l_e_c_t_B_i_t_s_P_t_r will be  updated  to  reflect  whether
  678.      there  are  still  more  characters  ready in the terminal's
  679.      input buffer.  TTdd__PPuuttCCooookkeedd overwrites the  value  at  *_s_i_g_-
  680.      _N_u_m_P_t_r;   if the value written is non-zero then it is a UNIX
  681.      signal number that should be applied to the calling  process
  682.      (this is used, for example, to generate SSIIGGTTTTIINN signals).
  683.  
  684.      When a process invokes an IOControl operation on the  termi-
  685.      nal,  TTdd__CCoonnttrroollCCooookkeedd  should  be called.  The arguments to
  686.      TTdd__CCoonnttrroollCCooookkeedd indicate the  IOControl  number  (_c_o_m_m_a_n_d),
  687.      plus  an  input  buffer  (_i_n_p_u_t_S_i_z_e and _i_n_p_u_t) and an output
  688.      buffer (*_o_u_t_p_u_t_S_i_z_e_P_t_r and _o_u_t_p_u_t).  The value  at  *_o_u_t_p_u_t_-
  689.      _S_i_z_e_P_t_r  will  be  modified to reflect the actualy number of
  690.      bytes of output data written at _o_u_t_p_u_t (this will be no more
  691.      than the original value of *_o_u_t_p_u_t_S_i_z_e_P_t_r).  The contents of
  692.      the input and output buffers are determined by the  specific
  693.      _c_o_m_m_a_n_d  being  requested.  See the documentation on the 4.3
  694.      BSD terminal  driver  for  details.   TTdd__CCoonnttrroollCCooookkeedd  will
  695.      modify  the  FFSS__RREEAADDAABBLLEE  and  FFSS__WWRRIITTAABBLLEE  bits of *_s_e_l_e_c_t_-
  696.      _B_i_t_s_P_t_r to reflect the state of  the  terminal's  input  and
  697.      output  buffers  when the IOControl completes.  TTdd__PPuuttCCooookkeedd
  698.      overwrites the value at *_s_i_g_N_u_m_P_t_r;  if the value written is
  699.      non-zero  then  it  is  a  UNIX signal number that should be
  700.      applied to the calling process.
  701.  
  702.      The Td library will invoke the _c_o_o_k_e_d_P_r_o_c, which was  passed
  703.      as  an  argument to TTdd__CCrreeaattee, when it wishes to give notice
  704.      of interesting events related to the cooked side of the ter-
  705.      minal.  _C_o_o_k_e_d_P_r_o_c should have the following structure:
  706.  
  707.           int
  708.           cookedProc(cookedData, operation, inputSize, input, outputSize, output)
  709.               ClientData cookedData;
  710.               int operation;
  711.               int inputSize;
  712.               char *input;
  713.               int outputSize;
  714.               char *output;
  715.           {
  716.            ...
  717.           }
  718.      The _c_o_o_k_e_d_D_a_t_a argument will be the same as  the  _c_o_o_k_e_d_D_a_t_a
  719.      argument  passed  to TTdd__CCrreeaattee.  It usually refers to a data
  720.      structure describing the interface to  processes  using  the
  721.      cooked  terminal.  The other arguments to _c_o_o_k_e_d_P_r_o_c and its
  722.  
  723.  
  724.  
  725. Sprite v.1.0         Printed:  April 9, 1990                   11
  726.  
  727.  
  728.  
  729.  
  730.  
  731.  
  732. Td                    C Library Procedures                     Td
  733.  
  734.  
  735.  
  736.      result have the same meaning as the arguments and result for
  737.      _r_a_w_P_r_o_c, except that  _o_p_e_r_a_t_i_o_n has different meanings.  The
  738.      values currently defined for _o_p_e_r_a_t_i_o_n are:
  739.  
  740.           TTDD__CCOOOOKKEEDD__SSIIGGNNAALL              A signal should  be  gen-
  741.                                         erated  for  the control-
  742.                                         ling process group  asso-
  743.                                         ciated with the terminal.
  744.                                         _I_n_p_u_t  will  point  to  a
  745.                                         structure  with  the fol-
  746.                                         lowing format:
  747.  
  748.                                         typedef struct {
  749.                                             int sigNum;
  750.                                             int groupID;
  751.                                         } Td_Signal;
  752.  
  753.                                         The _s_i_g_N_u_m field gives  a
  754.                                         UNIX  signal number (e.g.
  755.                                         SSIIGGIINNTT),   and    _g_r_o_u_p_I_D
  756.                                         identifies  the  control-
  757.                                         ling  process  group  for
  758.                                         the terminal.  _C_o_o_k_e_d_P_r_o_c
  759.                                         is not expected to return
  760.                                         any output data.
  761.  
  762.           TTDD__CCOOOOKKEEDD__RREEAADDSS__OOKK            There  is  now   readable
  763.                                         data  in the input buffer
  764.                                         associated with the  ter-
  765.                                         minal,  so  that the next
  766.                                         call to TTdd__GGeettCCooookkeedd will
  767.                                         not  return  EEWWOOUULLDDBBLLOOCCKK.
  768.                                         If  there  is  a  waiting
  769.                                         process,  it should prob-
  770.                                         ably be woken up.   There
  771.                                         is  no input data or out-
  772.                                         put data for this  opera-
  773.                                         tion.
  774.  
  775.           TTDD__CCOOOOKKEEDD__WWRRIITTEESS__OOKK           The output buffer for the
  776.                                         terminal  is  now  empty.
  777.                                         If  there  is  a  process
  778.                                         waiting  to do output, it
  779.                                         should probably be  woken
  780.                                         up.   There  is  no input
  781.                                         data or output  data  for
  782.                                         this operation.
  783.  
  784.  
  785. PPSSEEUUDDOO--DDEEVVIICCEE IINNTTEERRFFAACCEE
  786.      The Td library also contains routines to connect the  cooked
  787.      side  of  a  terminal to a pseudo-device.  The pseudo-device
  788.  
  789.  
  790.  
  791. Sprite v.1.0         Printed:  April 9, 1990                   12
  792.  
  793.  
  794.  
  795.  
  796.  
  797.  
  798. Td                    C Library Procedures                     Td
  799.  
  800.  
  801.  
  802.      routines use the facilities of the Pdev  library,  which  in
  803.      turn requires that the application use the FFss__SSeelleecctt library
  804.      to manage I/O channels.  The non-pseudo-device  portions  of
  805.      the Td library may be used without also using FFss__SSeelleecctt.
  806.  
  807.      TTdd__CCrreeaatteePPddeevv creates a pseudo-device file and arranges  for
  808.      the  file  to  have terminal-like behavior by associating it
  809.      with  a  terminal  managed  by   the   Td   library.    Once
  810.      TTdd__CCrreeaatteePPddeevv  has  been  called,  the pseudo-device and the
  811.      cooked side of its terminal will be  managed  automatically.
  812.      However,  it  is  up to TTdd__CCrreeaatteePPddeevv's caller to manage the
  813.      raw side of the pseudo-terminal.  The  _r_a_w_P_r_o_c  and  _r_a_w_D_a_t_a
  814.      arguments to TTdd__CCrreeaatteePPddeevv are the same as the corresponding
  815.      arguments  to  TTdd__CCrreeaattee  (TTdd__CCrreeaatteePPddeevv  passes   them   to
  816.      TTdd__CCrreeaattee  when  it  creates  the terminal).  If the _t_e_r_m_P_t_r
  817.      argument to TTdd__CCrreeaatteePPddeevv is not  NULL,  then  TTdd__CCrreeaatteePPddeevv
  818.      stores  the  Td_Terminal  token  for  the pseudo-terminal at
  819.      *_t_e_r_m_P_t_r; this allows the application to  invoke  procedures
  820.      like TTdd__PPuuttRRaaww.
  821.  
  822.      The name of the pseudo-device file created by  TTdd__CCrreeaatteePPddeevv
  823.      may  be specified in either of two ways.  If the _r_e_a_l_N_a_m_e_P_t_r
  824.      argument to TTdd__CCrreeaatteePPddeevv is NULL, then  the  _n_a_m_e  argument
  825.      gives the complete name of the pseudo-device file.  If _r_e_a_l_-
  826.      _N_a_m_e_P_t_r is not NULL, then the  pseudo-device  file  will  be
  827.      created  in  a  host-specific  directory  for the machine on
  828.      which the program is running, and the file  name  will  have
  829.      the form _n_a_m_e_X_X, where _X_X is a small integer chosen to avoid
  830.      conflict with other  files  that  have  the  same  _n_a_m_e.   A
  831.      pointer to the complete name will be stored in *_r_e_a_l_N_a_m_e_P_t_r;
  832.      the storage for the name is allocated by mmaalllloocc  and  should
  833.      eventually be freed by TTdd__CCrreeaatteePPddeevv's caller.
  834.  
  835.      TTdd__CCrreeaatteePPddeevv normally  returns  a  token  for  the  pseudo-
  836.      terminal.   If  the  pseudo-device  couldn't be opened, then
  837.      NULL is returned and the variable ppddeevv__EErrrroorrMMssgg points to  a
  838.      string describing what went wrong.
  839.  
  840.      The only use for the token returned by TTdd__CCrreeaatteePPddeevv  is  to
  841.      pass  it  to  TTdd__DDeelleetteePPddeevv.  When this happens, the pseudo-
  842.      device is closed and the associated terminal is destroyed by
  843.      calling TTdd__DDeelleettee.
  844.  
  845.  
  846. BBUUFFFFEERRIINNGG
  847.      The input buffer for a Td_Terminal  grows  automatically  to
  848.      accommodate  as  much data as is present:  there is no upper
  849.      limit on  its  size.   The  output  buffer  will  also  grow
  850.      automatically:   TTdd__PPuuttCCooookkeedd  always  accepts  all the data
  851.      passed to it.  However, it is usually a bad idea to buffer a
  852.      very large number of characters on output, since these char-
  853.      acters will have to be output even if the process is  killed
  854.  
  855.  
  856.  
  857. Sprite v.1.0         Printed:  April 9, 1990                   13
  858.  
  859.  
  860.  
  861.  
  862.  
  863.  
  864. Td                    C Library Procedures                     Td
  865.  
  866.  
  867.  
  868.      with  a  control-C.   The  _b_u_f_f_e_r_S_i_z_e  argument to TTdd__CCrreeaattee
  869.      specifies a nominal output buffer size;  whenever more  than
  870.      this  many  characters  are buffered, TTdd__PPuuttCCooookkeedd will turn
  871.      off the FFSS__WWRRIITTAABBLLEE bit in *_s_e_l_e_c_t_B_i_t_s_P_t_r to  indicate  that
  872.      the  buffer  is  nominally  full;  the enclosing application
  873.      should then refuse to  accept  more  characters  for  output
  874.      (e.g.,  by  suspending the process).  When the output buffer
  875.      empties,    _c_o_o_k_e_d_P_r_o_c    will    be    invoked    with    a
  876.      TTDD__CCOOOOKKEEDD__WWRRIITTEESS__OOKK command.
  877.  
  878.  
  879. EEXXAAMMPPLLEESS
  880.      The best way to learn how to use the Td library is  to  look
  881.      at examples in the Sprite source code.  The simplest example
  882.      is the mmkkttttyy  program;   other  examples  are  rrllooggiinndd  (the
  883.      remote-login  server) and ttxx (a window-based terminal emula-
  884.      tor).
  885.  
  886.  
  887. KKEEYYWWOORRDDSS
  888.      4.3 BSD, pseudo-device, terminal driver
  889.  
  890.  
  891.  
  892.  
  893.  
  894.  
  895.  
  896.  
  897.  
  898.  
  899.  
  900.  
  901.  
  902.  
  903.  
  904.  
  905.  
  906.  
  907.  
  908.  
  909.  
  910.  
  911.  
  912.  
  913.  
  914.  
  915.  
  916.  
  917.  
  918.  
  919.  
  920.  
  921.  
  922.  
  923. Sprite v.1.0         Printed:  April 9, 1990                   14
  924.  
  925.  
  926.  
  927.